package com.lizardmind.haofudoctor.ui.main

import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.view.View
import com.blankj.utilcode.util.EncryptUtils
import com.blankj.utilcode.util.FileUtils
import com.bumptech.glide.Glide
import com.linxiao.framework.activity.BaseActivity
import com.linxiao.framework.net.cache.CacheManager
import com.linxiao.framework.util.FileUtil
import com.linxiao.framework.util.getDataBinding
import com.linxiao.framework.util.ke
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.ActivityLoginBinding
import com.lizardmind.haofudoctor.manager.ImgManager
import com.lizardmind.haofudoctor.manager.setImageUrl
import com.lizardmind.haofudoctor.other.RongConnectEvent
import io.rong.imkit.RongIM
import io.rong.imlib.model.Conversation
import kotlinx.android.synthetic.main.include_title_text.*
import org.greenrobot.eventbus.Subscribe
import org.jetbrains.anko.intentFor
import org.jetbrains.anko.toast
import java.io.File
import java.lang.ref.WeakReference

class LoginActivity : BaseActivity() {

    val binding by lazy { getDataBinding<ActivityLoginBinding>(R.layout.activity_login) }

    override fun onCreatRootView(): View = binding.root

    override fun onInitView(savedInstanceState: Bundle?) {
        setEvent(true)
        binding.apply {
            vm = ViewModelProviders.of(this@LoginActivity).get(LoginVM::class.java)
            titleText.text = "登陆"

            vm?.activity = WeakReference(this@LoginActivity)
            lifecycle.addObserver(vm!!)

//            ImgManager.showImg(vm!!.img,imageView6)
        }

    }

    @Subscribe
    public fun getRongConnect(rc: RongConnectEvent){
        if(rc.status){
            toast("登陆成功")
//            startActivity(intentFor<MainActivity>())
            RongIM.getInstance().startSubConversationList(this, Conversation.ConversationType.PRIVATE)
        }else{
            toast("登陆失败")
        }
    }
}
